
/*
 * Java class "EnemyList.java" generated from Poseidon for UML.
 * Poseidon for UML is developed by <A HREF="http://www.gentleware.com">Gentleware</A>.
 * Generated with <A HREF="http://jakarta.apache.org/velocity/">velocity</A> template engine.
 */
package jcs;

import java.lang.String;


/**
 * <p></p>
 * @poseidon-object-id [sm$a6a21a:ffe8ee1f0d:-7feb]
 */
public class EnemyList {

  ///////////////////////////////////////
  // attributes


/**
 * <p>Represents ...</p>
 * @poseidon-object-id [sm$a6a21a:ffe8ee1f0d:-7fea]
 */
    private Enemy[] enemies; 

/**
 * <p>Represents ...</p>
 * @poseidon-object-id [sm$a6a21a:ffe8ee1f0d:-7eb4]
 */
    private int count; 

   ///////////////////////////////////////
   // associations

/**
 * <p></p>
 * @poseidon-object-id [sm$a6a21a:ffe8ee1f0d:-7fe8]
 */
    private Seth seth; 


  ///////////////////////////////////////
  // operations


/**
 * <p>Does ...</p>
 * 
 * @poseidon-object-id [sm$a6a21a:ffe8ee1f0d:-7f96]
 * @return 
 */
    public Enemy getOldest() {        
        int oldest = 0;
        for(int i = 0; i < enemies.length && enemies[i] != null; i++)
        {
        	if(enemies[i] != null)
        	{
        		if(enemies[i].getTicks() < enemies[oldest].getTicks() )
        			oldest = i;
        	}
        }
        return enemies[oldest];
    } // end getOldest        

/**
 * <p>Does ...</p>
 * 
 * @poseidon-object-id [sm$a6a21a:ffe8ee1f0d:-7f80]
 * @return 
 * @param _name 
 */
    public Enemy get(String _name) {        
        Enemy enemy = this.find(_name);
        if(enemy == null)
        {
            enemy = new Enemy(_name, seth);
            add(enemy);
        }
        return enemy;
    } // end get        

/**
 * <p>Does ...</p>
 * 
 * @poseidon-object-id [sm$a6a21a:ffe8ee1f0d:-7f7f]
 * @param _enemy 
 */
    private void add(Enemy _enemy) {        
        int i = enemies.length - 1;
        while( i >= 0 && enemies[i] == null)
        {
            i--;
        }
        enemies[i+1] = _enemy;
        count++;
    } // end add        

/**
 * <p>Does ...</p>
 * 
 * @poseidon-object-id [sm$a6a21a:ffe8ee1f0d:-7f7e]
 */
    public void spew() {        
                	for(int j = 0; j < enemies.length; j++)
        		{
        			if(enemies[j] != null)
        				System.out.println("enemies["+j+"] = " + enemies[j].toString());
        			else
        				System.out.println("enemies["+j+"] = null");			
        		}
    } // end spew        

/**
 * <p>Does ...</p>
 * 
 * @poseidon-object-id [sm$a6a21a:ffe8ee1f0d:-7f32]
 * @param _name 
 */
    public void remove(String _name) {        
        boolean found = false;
        for(int i = 0; i < enemies.length && enemies[i] != null; i++)
        {
            if(found == true)
            {                
                enemies[i-1] = enemies[i];
            }
            else if(_name.equals(enemies[i].getName()))
            {	
                found = true;
            }
            
            // Set the last one to null
            if((i+1) == enemies.length || enemies[i+1] == null)
            {                
        		enemies[i] = null;
            }
        }
        count--;
    } // end remove        

/**
 * <p>Does ...</p>
 * 
 * @poseidon-object-id [sm$a6a21a:ffe8ee1f0d:-7f05]
 * @return 
 * @param _name 
 */
    public Enemy find(String _name) {        
            Enemy found = null;
            for(int i = 0; i < enemies.length && found == null && enemies[i] != null; i++)
            {
        	if(enemies[i].getName().equals(_name))
                {
                    found = enemies[i];
        	}
            }
            return found;
    } // end find        

/**
 * <p>Does ...</p>
 * 
 * @poseidon-object-id [sm$a6a21a:ffe8ee1f0d:-7eb5]
 * @return 
 */
    public int getCount() {        
        return count;
    } // end getCount        

/**
 * <p>Does ...</p>
 * 
 * @poseidon-object-id [sm$a6a21a:ffe8ee1f0d:-7eb3]
 * @param _seth 
 */
    public  EnemyList(Seth _seth) {        
        enemies = new Enemy[_seth.getOthers()];
        seth = _seth;
        count = 0;
    } // end EnemyList        

/**
 * 
 * 
 * @poseidon-object-id [sm$31b810:ffff82645c:-7feb]
 * @return 
 */
    public Enemy[] getEnemies() {        
        return enemies;
    } // end getEnemies        

 } // end EnemyList


